{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## python module部分\n",
    "\n",
    "from tornado\n",
    "\n",
    "class OrderModule(tornado.web.UIModule):\n",
    "    ## 模版中调用的方法\n",
    "    def cal_total(self, price, nums):\n",
    "        return price * nums\n",
    "    \n",
    "    def render(self, order, *args, **kwargs):\n",
    "        return self.render_string(\"ui_modules/order-list.html\", order=order, cal_total=self.cal_total)\n",
    "    \n",
    "    ## 返回字符串css\n",
    "    def embedded_css(self):\n",
    "        return \"body {background-color: green;}\"\n",
    "    \n",
    "    ## 加载文件css\n",
    "    def css_files(self):\n",
    "        ## static 目录下的路径\n",
    "        return [\"ui_modules/order-list.css\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## settings 参数配置\n",
    "\n",
    "settings = {\n",
    "    \"static_path\": \"path/to/static\",\n",
    "    \"static_url_prefix\": \"/static/\",\n",
    "    \"template_path\": \"templates\",\n",
    "    \"ui_modules\": {\n",
    "        \"OrderModule\": OrderModule,\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## OrderModule模板调用\n",
    "\n",
    "{% for order in orders %}\n",
    "    {% module OrderModule(order) %}\n",
    "{% end %}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
